package leetcode.code0171;

import leetcode.IDebug;

public class Solution implements IDebug {

	static int[] pow;
	static {
		pow = new int[8];
		for (int i = 0; i < 8; i++) {
			pow[i] = (int) Math.pow(26, i);
		}
	}

	public int titleToNumber(String columnTitle) {
		char[] cs = columnTitle.toCharArray();
		int ans = 0;
		int len = cs.length;
		for (int i = len - 1; i >= 0; i--) {
			ans += pow[len - i - 1] * (cs[i] - 64);
		}
		return ans;
	}

	public int titleToNumber1(String columnTitle) {
		char[] cs = columnTitle.toCharArray();
		int ans = 0;
		int n = 0;
		for (int i = cs.length - 1; i >= 0; i--) {
			ans += (int) Math.pow(26, n++) * (cs[i] - 64);
		}
		return ans;
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {

	}

}
